package com.letchat.controller;

import com.letchat.pojo.CommentParent;
import com.letchat.pojo.Result;
import com.letchat.service.impl.CommentService;
import com.letchat.service.impl.SubjectService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/subject")
public class SubjectController {

    @Autowired
    SubjectService subjectService;
    @Autowired
    CommentService commentService;

    /**
     * 主题详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getSubjectDetailById(@PathVariable Integer id) {
        log.info("主题id{}",id);
        return Result.success(subjectService.getSubjectDetailById(id));
    }

    /**
     * 发布父评论
     * @param commentParent
     * @return
     */
    @PostMapping("/parent")
    public Result makeAParentComment(@RequestBody CommentParent commentParent){
        commentService.makeAParentComment(commentParent);
        return Result.success();
    }

    /**
     * 删除主题
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result deleteSubject(@PathVariable Integer id){
        subjectService.deleteSubject(id);
        return Result.success();
    }

    /**
     * 分页条件查询
     * @return
     */

    @GetMapping
    public Result sujectList(@RequestParam(defaultValue = "1") Integer page,
                             @RequestParam(defaultValue = "10")Integer pageSize,
                                String subject){
        return Result.success(subjectService.sujectList(page, pageSize,subject));
    }
}
